package com.magold.logic.polygon;

import org.andengine.entity.scene.Scene;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.magold.logic.ISpriteLogic;
import com.magold.logic.LogicPhysicsHelper;
import com.magold.logic.LogicSpriteWrapper;
import com.magold.sprite.IMultiTextureSprite;
import com.magold.sprite.PolygonSprite;

public class RectShape extends PrimitiveShape {
	private float mWidth, mHeight;
	
	public RectShape(float pWidth, float pHeight) {
		mWidth = pWidth;
		mHeight = pHeight;
	}
	
	@Override
	public void createSceneData(float pX, float pY, float pRotation,
			float pScale, Scene pScene, ISpriteLogic pCollisionHandler,
			ITiledTextureRegion pRegion, VertexBufferObjectManager vbom)
	{
		float[] mXCoors = new float[] {0, mWidth, mWidth, 0};
		float[] mYCoors = new float[] {0, 0, mHeight, mHeight};
		IMultiTextureSprite raw = new PolygonSprite(pX, pY, mXCoors, mYCoors, pRegion, vbom);
		mSprite = LogicSpriteWrapper.wrap(raw, pScale, null, pCollisionHandler, pRotation, pScene);
	}

	@Override
	public void createPhysicsData(PhysicsWorld pWorld, BodyType pBodyType, FixtureDef pFixtureDef) {
		Body body = PhysicsFactory.createBoxBody(pWorld, mSprite, pBodyType, pFixtureDef);
		mConnector = LogicPhysicsHelper.connectBody(pWorld, body, mSprite);
	}

}
